package com.mes.web.controller.biz;

import java.util.List;
import java.util.HashMap;
import java.util.Map;
import com.mes.common.annotation.Log;
import com.mes.common.core.domain.AjaxResult;
import com.mes.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.mes.common.core.domain.model.LoginUser;
import com.mes.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mes.common.enums.BusinessType;
import com.mes.common.utils.poi.ExcelUtil;
import com.mes.framework.cache.DictUtils;
import javax.validation.constraints.*;

import com.mes.framework.web.service.TokenService;
import org.springframework.web.bind.annotation.*;
import com.mes.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.mes.biz.domain.BizOrderAccessory;
import com.mes.biz.service.BizOrderAccessoryService;

/**
 * 销售单配件信息Controller
 * @author wy
 * @email wy
 * @date 2023-10-06
 */
@RestController
@RequestMapping("/biz/bizOrderAccessory")
public class BizOrderAccessoryController extends BaseController {

    @Autowired
    private BizOrderAccessoryService bizOrderAccessoryService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询销售单配件信息列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizOrderAccessory:list')")
    @GetMapping("/list")
    public R<PageInfo> list(BizOrderAccessory bizOrderAccessory, HttpServletRequest request, HttpServletResponse response) {
        bizOrderAccessory.setPage(new PageDomain(request, response));
        return R.data(bizOrderAccessoryService.findPage(bizOrderAccessory));
    }

    /**
     * 获取销售单配件信息详细信息
     */
    @GetMapping(value = "/{id}")
    public R<BizOrderAccessory> detail(@PathVariable("id") String id) {
        return R.data(bizOrderAccessoryService.get(id));
    }

    /**
     * 新增销售单配件信息
     */
    @Log(title = "销售单配件信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  BizOrderAccessory bizOrderAccessory) {
        return R.status(bizOrderAccessoryService.save(bizOrderAccessory));
    }

    /**
     * 修改销售单配件信息
     */
    @Log(title = "销售单配件信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BizOrderAccessory bizOrderAccessory) {
        return R.status(bizOrderAccessoryService.save(bizOrderAccessory));
    }

    /**
     * 删除销售单配件信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizOrderAccessory:remove')")
    @Log(title = "销售单配件信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(bizOrderAccessoryService.deleteBizOrderAccessoryByIds(ids));
    }


    /**
     * 导出销售单配件信息列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizOrderAccessory:export')")
    @Log(title = "销售单配件信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BizOrderAccessory bizOrderAccessory) {
        List<BizOrderAccessory> list = bizOrderAccessoryService.findList(bizOrderAccessory);
        ExcelUtil<BizOrderAccessory> util = new ExcelUtil<BizOrderAccessory>(BizOrderAccessory.class);
        return util.exportExcel(list, "销售单配件信息数据");
    }

    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }


    @Log(title = "销售单配件信息", businessType = BusinessType.INSERT)
    @PostMapping("/addAccessory")
    public AjaxResult addAccessory(@RequestBody @Validated  BizOrderAccessory bizOrderAccessory) {
        return AjaxResult.success(bizOrderAccessoryService.create(bizOrderAccessory));
    }

    /**
     * 修改销售单配件信息
     */
    @Log(title = "销售单配件信息", businessType = BusinessType.UPDATE)
    @PostMapping("/editAccessory")
    public R editAccessory(@RequestBody @Validated BizOrderAccessory bizOrderAccessory) {
        return R.status(bizOrderAccessoryService.update(bizOrderAccessory));
    }

    @GetMapping("/appletList")
    public R<PageInfo> appletList(BizOrderAccessory bizOrderAccessory, HttpServletRequest request, HttpServletResponse response) {
        bizOrderAccessory.setPage(new PageDomain(request, response));
//        LoginUser loginUser = tokenService.getLoginUser(request);
//        bizOrderAccessory.setCreateBy(loginUser.getUserId());
        return R.data(bizOrderAccessoryService.findPage(bizOrderAccessory));
    }
}
